package com.qingke.project_management;


import java.util.regex.Pattern;

import com.qingke.project_management.command.*;
import com.qingke.project_management.command_enum.CommandCode;
import com.qingke.project_management.pojo.*;

/**
 * @author lz
 *
 */
public class App 
{
	
	private User user = null;

    public User getUser() {
		return user;
	}
    
    public void setUser(User user) {
		this.user = user;
	}

    private static App instance = new App();
    public static App getInstance(){
    	return instance;
    }

	public static void main(String[] args){
		Console.println("=====开始=====");
		Console.printHelp();
		while(true){
			Command command = getCmd();
			if(command==null){
				continue;
			}
			command.execute();
		}
    }

	public static Command getCmd(){
		
		String cmd=null;
		Pattern pattern = Pattern.compile("[0-9a-zA-Z]+");
		while (true) {
			cmd = Console.askInput("cmd");
			if(!pattern.matcher(cmd).find()){
				Console.println("别乱摁，好好输入");
				continue;
			}
			break;
		}
		
		CommandCode cmdCode = null;
		try {
			cmdCode=CommandCode.valueOf(cmd.toUpperCase());
		} catch (Exception e) {
			Console.println("命令输入有误，请重新输入");
			return null;
		}
		return new CommandFactory().buildCommand(cmdCode);
	}
}
